﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using IronBrokers.ClientManager.Model;

namespace IronBrokers.ClientManager
{
    public class ClientServant : ServiceBase, IClientServant
    {
        #region Subscribe
        public TicketResponse Subscribe(string userName, string password)
        {
            try
            {
                Model.Ticket ticket = PersistenceManager.Subscribe(userName, password);
                this.CreateExchange(ticket, password);
                return new TicketResponse(ticket);
            }
            catch (Exception ex)
            {
                // TODO: log error
                return new TicketResponse(ex);
            }
        } 
        #endregion

        #region Unsubscribe
        public Response Unsubscribe(Guid ticketID)
        {
            try
            {
                Ticket ticket = PersistenceManager.Unsubscribe(ticketID);
                this.DestroyExchange(ticket);
                return new Response();
            }
            catch (Exception ex)
            {
                // TODO: log error
                return new Response(ex);
            }
        } 
        #endregion

        #region CreateExchange
        private void CreateExchange(Model.Ticket ticket, String plainPassword)
        {

        }
        #endregion

        #region DestroyExchange
        private void DestroyExchange(Model.Ticket ticket)
        {

        }
        #endregion
    }
}
